package cn.android.basic

/**
 * <br>createBy Gw
 * <br>createTime: 2021/7/9 10:55
 * 探讨 inline 关键字在无高阶函数下使用对性能优化的影响
 */

inline fun log(tag:String, msg:String){
    val r = tag+msg
}

inline fun log(msg: String){
    log("test", msg)
}

fun main() {
    var ago = System.currentTimeMillis()
    for (i in 1..1_0000_0000) {
        log("哈哈哈")
    }
    println("RESULT: " + (System.currentTimeMillis() - ago))
    /*
     * 实验:
     * -------------------------------------
     * | 序号 | 无内联耗时(ms) | 有内联耗时(ms) |
     * -------------------------------------
     * |  1  |     3098     |     2548     |
     * -------------------------------------
     * |  2  |     2617     |     2505     |
     * -------------------------------------
     * |  3  |     2400     |     2273     |
     * -------------------------------------
     * |  4  |     2259     |     3593     |
     * -------------------------------------
     * |  5  |     2441     |     2416     |
     * -------------------------------------
     * |  6  |     3237     |     2425     |
     * -------------------------------------
     * |  7  |     3281     |     2256     |
     * -------------------------------------
     * |  8  |     3048     |     2402     |
     * -------------------------------------
     * |  9  |     3103     |     2265     |
     * -------------------------------------
     * | 10  |     2293     |     2300     |
     * -------------------------------------
     *          无内联     有内联
     * 平均数:   2777.7    2498.3
     */
}